﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Common="http://imagin.tech/imagin/common"
    xmlns:Controls.Common="http://imagin.tech/imagin/controls/common">
    <Common:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>

    <Style x:Key="{x:Type DataGridCell}" TargetType="{x:Type DataGridCell}">
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="Foreground"  Value="{DynamicResource Brush.DataGridCell.Foreground}"/>
        <Setter Property="FontSize" Value="15"/>
        <Setter Property="Padding" Value="5"/>
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DataGridCell}">
                    <ControlTemplate.Resources>
                        <Style TargetType="{x:Type TextBlock}">
                            <Setter Property="TextTrimming" Value="CharacterEllipsis"/>
                        </Style>
                    </ControlTemplate.Resources>
                    <Border 
                        Background="{TemplateBinding Background}" 
                        BorderBrush="{TemplateBinding BorderBrush}" 
                        BorderThickness="{TemplateBinding BorderThickness}" 
                        Padding="{TemplateBinding Padding}" 
                        SnapsToDevicePixels="True">
                        <ContentPresenter 
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            TextElement.Foreground="{TemplateBinding Foreground}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <!--
        <Style.Triggers>
            <Trigger Property="IsSelected" Value="True">
                <Setter Property="Background"  Value="{DynamicResource Brush.DataGridCell.Selected.Background}"/>
                <Setter Property="Foreground"  Value="{DynamicResource Brush.DataGridCell.Selected.Foreground}"/>
            </Trigger>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Background"  Value="{DynamicResource Brush.DataGridCell.MouseOver.Background}"/>
                <Setter Property="Foreground"  Value="{DynamicResource Brush.DataGridCell.MouseOver.Foreground}"/>
            </Trigger>
        </Style.Triggers>
        -->
    </Style>

    <Style x:Key="{x:Type DataGridRow}" TargetType="{x:Type DataGridRow}">
        <Setter Property="Controls.Common:FrameworkElementExtensions.BorderBrush" Value="{DynamicResource Brush.DataGridRow.Border}" />
        <Setter Property="Controls.Common:FrameworkElementExtensions.BorderThickness" Value="1" />
        <Setter Property="TextElement.Foreground" Value="{DynamicResource Brush.DataGridRow.Foreground}" />
        <Setter Property="Validation.ErrorTemplate" Value="{x:Null}" />
        <Setter Property="ValidationErrorTemplate">
            <Setter.Value>
                <ControlTemplate>
                    <TextBlock Foreground="Red"
                        Margin="2,0,0,0"
                        Text="!"
                        VerticalAlignment="Center" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DataGridRow}">
                    <Border
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        Background="{TemplateBinding Background}">
                        <Border
                            Background="{Binding Path=(Controls.Common:FrameworkElementExtensions.Background), RelativeSource={RelativeSource TemplatedParent}}"
                            BorderBrush="{Binding Path=(Controls.Common:FrameworkElementExtensions.BorderBrush), RelativeSource={RelativeSource TemplatedParent}}"
                            BorderThickness="{Binding Path=(Controls.Common:FrameworkElementExtensions.BorderThickness), RelativeSource={RelativeSource TemplatedParent}}"
                            SnapsToDevicePixels="True">
                            <SelectiveScrollingGrid>
                                <SelectiveScrollingGrid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="*" />
                                </SelectiveScrollingGrid.ColumnDefinitions>
                                <SelectiveScrollingGrid.RowDefinitions>
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="Auto" />
                                </SelectiveScrollingGrid.RowDefinitions>
                                <DataGridCellsPresenter 
                                    Grid.Column="1"
                                    ItemsPanel="{TemplateBinding ItemsPanel}"
                                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                                <DataGridDetailsPresenter 
                                    Grid.Column="1"
                                    Grid.Row="1"
                                    SelectiveScrollingGrid.SelectiveScrollingOrientation="{Binding AreRowDetailsFrozen, ConverterParameter={x:Static SelectiveScrollingOrientation.Vertical}, Converter={x:Static DataGrid.RowDetailsScrollingConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"
                                    Visibility="{TemplateBinding DetailsVisibility}" />
                                <DataGridRowHeader Grid.RowSpan="2"
                                    SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical"
                                    Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.Row}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" />
                            </SelectiveScrollingGrid>
                        </Border>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsMouseOver" Value="True" />
                    <Condition Property="IsSelected" Value="False" />
                </MultiTrigger.Conditions>
                <Setter Property="Controls.Common:FrameworkElementExtensions.Background" Value="{DynamicResource Brush.DataGridRow.MouseOver.Background}" />
                <Setter Property="Controls.Common:FrameworkElementExtensions.BorderBrush" Value="{DynamicResource Brush.DataGridRow.MouseOver.Border}" />
            </MultiTrigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsSelected" Value="True" />
                    <Condition Property="Selector.IsSelectionActive" Value="False" />
                </MultiTrigger.Conditions>
                <Setter Property="Controls.Common:FrameworkElementExtensions.Background" Value="{DynamicResource Brush.DataGridRow.Selected.Background}" />
                <Setter Property="Controls.Common:FrameworkElementExtensions.BorderBrush" Value="{DynamicResource Brush.DataGridRow.Selected.Border}" />
            </MultiTrigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsSelected" Value="True" />
                    <Condition Property="Selector.IsSelectionActive" Value="True" />
                </MultiTrigger.Conditions>
                <Setter Property="Controls.Common:FrameworkElementExtensions.Background" Value="{DynamicResource Brush.DataGridRow.Selected.Active.Background}" />
                <Setter Property="Controls.Common:FrameworkElementExtensions.BorderBrush" Value="{DynamicResource Brush.DataGridRow.Selected.Active.Border}" />
                <Setter Property="Foreground" Value="{DynamicResource Brush.DataGridRow.Selected.Active.Foreground}" />
            </MultiTrigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsSelected" Value="False" />
                    <Condition Property="ItemsControl.AlternationIndex" Value="0" />
                    <Condition Property="IsMouseOver" Value="False" />
                </MultiTrigger.Conditions>
                <Setter Property="Controls.Common:FrameworkElementExtensions.Background" Value="{DynamicResource Brush.DataGridRow.Even.Background}"/>
            </MultiTrigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsSelected" Value="False" />
                    <Condition Property="ItemsControl.AlternationIndex" Value="1" />
                    <Condition Property="IsMouseOver" Value="False" />
                </MultiTrigger.Conditions>
                <Setter Property="Controls.Common:FrameworkElementExtensions.Background" Value="{DynamicResource Brush.DataGridRow.Odd.Background}"/>
            </MultiTrigger>
        </Style.Triggers>
    </Style>
    
    <Style x:Key="Style.DataGridColumnHeader.Thumb" TargetType="Thumb">
        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="Background" Value="{DynamicResource Brush.DataGridColumnHeader.Thumb}"/>
        <Setter Property="HorizontalContentAlignment" Value="Center"/>
        <Setter Property="Width" Value="18"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Border Background="Transparent">
                        <Rectangle 
                            Fill="{TemplateBinding Background}"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                            Width="1"/>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="Style.DataGridColumnHeader" TargetType="{x:Type DataGridColumnHeader}">
        <Setter Property="BorderBrush" Value="{DynamicResource Brush.DataGridColumnHeader.Border}" />
        <Setter Property="BorderThickness" Value="1,0,1,1" />
        <Setter Property="Cursor" Value="Hand" />
        <Setter Property="Foreground" Value="{DynamicResource Brush.DataGridColumnHeader.Foreground}" />
        <Setter Property="HorizontalContentAlignment" Value="Center" />
        <Setter Property="Margin" Value="-1,0,0,0" />
        <Setter Property="MinWidth" Value="0" />
        <Setter Property="MinHeight" Value="30" />
        <Setter Property="Padding" Value="10,0" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Border
                            Grid.ColumnSpan="2" 
                            BorderThickness="{TemplateBinding BorderThickness}" 
                            Background="{TemplateBinding Background}" 
                            BorderBrush="{TemplateBinding BorderBrush}" />
                        <ContentPresenter
                            Margin="6,3" 
                            VerticalAlignment="Center"/>
                        <Path
                            Grid.Column="1" 
                            x:Name="SortArrow" 
                            Data="M0,0 L1,0 0.5,1 z" 
                            Fill="{TemplateBinding Foreground}"
                            Height="6" 
                            Margin="0,0,8,0"  
                            RenderTransformOrigin="0.5,0.4"
                            Stretch="Fill" 
                            VerticalAlignment="Center" 
                            Visibility="Collapsed" 
                            Width="8"/>
                        <Thumb 
                            Grid.ColumnSpan="2" 
                            x:Name="PART_RightHeaderGripper" 
                            Cursor="SizeWE"
                            Margin="-8,0,-9,0"
                            HorizontalAlignment="Right"
                            Style="{StaticResource Style.DataGridColumnHeader.Thumb}"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="SortDirection" Value="Ascending">
                            <Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />
                            <Setter TargetName="SortArrow" Property="RenderTransform">
                                <Setter.Value>
                                    <RotateTransform Angle="180" />
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                        <Trigger Property="SortDirection" Value="Descending">
                            <Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <!--
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
                    <Border 
                        Name="PART_Border" 
                        Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        Padding="{TemplateBinding Padding}">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <ContentPresenter 
                                Grid.Column="0"
                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                Margin="6,3"
                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                            <Path 
                                Grid.Column="1" 
                                x:Name="SortArrow" 
                                Data="M 0 4 L 4 0 L 8 4 Z" 
                                Fill="{TemplateBinding Foreground}" 
                                Height="6" 
                                HorizontalAlignment="Center" 
                                Margin="0,0,8,0"  
                                RenderTransformOrigin="0.5,0.4" 
                                VerticalAlignment="Center" 
                                Visibility="Collapsed" 
                                Width="8"/>
                            <Thumb 
                                Grid.Column="2" 
                                Cursor="SizeWE"
                                Margin="-8,0,-9,0"
                                HorizontalAlignment="Right"
                                Style="{StaticResource Style.DataGridColumnHeader.Thumb}"/>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="SortDirection" Value="Ascending">
                            <Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />
                            <Setter TargetName="SortArrow" Property="RenderTransform">
                                <Setter.Value>
                                    <RotateTransform Angle="180" />
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                        <Trigger Property="SortDirection" Value="Descending">
                            <Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        -->
        <Style.Triggers>
            <Trigger Property="SortDirection" Value="{x:Null}">
                <Setter Property="Background" Value="{DynamicResource Brush.DataGridColumnHeader.Background}" />
            </Trigger>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Background" Value="{DynamicResource Brush.DataGridColumnHeader.MouseOver.Background}" />
                <Setter Property="BorderBrush" Value="{DynamicResource Brush.DataGridColumnHeader.MouseOver.Border}" />
                <Setter Property="Foreground" Value="{DynamicResource Brush.DataGridColumnHeader.MouseOver.Foreground}" />
            </Trigger>
            <Trigger Property="IsPressed" Value="True">
                <Setter Property="Background" Value="{DynamicResource Brush.DataGridColumnHeader.Pressed.Background}" />
                <Setter Property="BorderBrush" Value="{DynamicResource Brush.DataGridColumnHeader.Pressed.Border}" />
                <Setter Property="Foreground" Value="{DynamicResource Brush.DataGridColumnHeader.Pressed.Foreground}" />
            </Trigger>
        </Style.Triggers>
    </Style>

    <Style x:Key="{x:Type DataGridRowHeader}" TargetType="{x:Type DataGridRowHeader}">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Padding" Value="5,0" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DataGridRowHeader}">
                    <Grid>
                        <Border 
                            BorderBrush="{Binding RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}, Path=HorizontalGridLinesBrush}"
                            Background="{TemplateBinding Background}"                                     
                            BorderThickness="{TemplateBinding BorderThickness}"
                            Padding ="{TemplateBinding Padding}">
                            <StackPanel Orientation="Horizontal">
                                <ContentPresenter 
                                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                    VerticalAlignment="Center"/>
                            </StackPanel>
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Background" Value="#11000000" />
                        </Trigger>
                        <Trigger Property="IsRowSelected" Value="True">
                            <Setter Property="Background" Value="#55FFFFFF" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="Style.DataGrid.SelectAll" TargetType="Button">
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="Background" Value="{DynamicResource Brush.DataGridColumnHeader.Background}" />
        <Setter Property="BorderBrush" Value="{DynamicResource Brush.DataGridColumnHeader.Border}" />
        <Setter Property="BorderThickness" Value="0,0,1,1"/>
        <Setter Property="Cursor" Value="Hand" />
        <Setter Property="HorizontalContentAlignment" Value="Center" />
        <Setter Property="Padding" Value="5,0" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Border 
                        Background="{TemplateBinding Background}" 
                        BorderBrush="{TemplateBinding BorderBrush}" 
                        BorderThickness="{TemplateBinding BorderThickness}"
                        Padding="{TemplateBinding Padding}">
                        <ContentPresenter 
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Background" Value="{DynamicResource Brush.DataGridColumnHeader.MouseOver.Background}"/>
            </Trigger>
            <Trigger Property="IsPressed" Value="True">
                <Setter Property="Background" Value="{DynamicResource Brush.DataGridColumnHeader.Pressed.Background}"/>
            </Trigger>
        </Style.Triggers>
    </Style>

    <Style x:Key="Style.DataGrid.ScrollViewer" TargetType="{x:Type ScrollViewer}">
        <Setter Property="CanContentScroll" Value="True"/>
        <Setter Property="VerticalScrollBarVisibility" Value="Auto"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ScrollViewer}">
                    <Border
                        Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        SnapsToDevicePixels="True">
                        <Grid ClipToBounds="True">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="{Binding ElementName=PART_VerticalScrollBar, Path=ActualWidth, Mode=OneWay}"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="{Binding ElementName=PART_HorizontalScrollBar, Path=ActualHeight, Mode=OneWay}"/>
                            </Grid.RowDefinitions>

                            <Button
                                Command="{x:Static DataGrid.SelectAllCommand}"
                                Focusable="False"
                                Style="{StaticResource Style.DataGrid.SelectAll}"
                                Width="{Binding CellsPanelHorizontalOffset, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"
                                Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.All}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}">
                                <Controls.Common:MaskedImage 
                                    Source="pack://application:,,,/Imagin.Styles;component/Images/BottomRightTriangle.png"/>
                            </Button>
                            <DataGridColumnHeadersPresenter
                                Panel.ZIndex="0" 
                                Grid.Column="1" 
                                Grid.ColumnSpan="2"
                                x:Name="PART_ColumnHeadersPresenter" 
                                Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.Column}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"/>
                            <Controls.Common:MaskedButton
                                Grid.Column="1" 
                                Grid.ColumnSpan="2"
                                Command="{x:Static Controls.Common:DataGridExtensions.AddCommand}"
                                CommandTarget="{Binding Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"
                                HorizontalAlignment="Right"
                                Padding="7,0"
                                Source="pack://application:,,,/Imagin.Styles;component/Images/PlusRound.png"
                                VerticalAlignment="Center"
                                Visibility="{Binding CanUserAddRows, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"/>
                            <ScrollContentPresenter
                                Grid.ColumnSpan="3"
                                Grid.Row="1"
                                x:Name="PART_ScrollContentPresenter"
                                CanContentScroll="{TemplateBinding CanContentScroll}"/>

                            <ScrollBar
                                Grid.Row="1"
                                Grid.Column="2"
                                Grid.RowSpan="1"
                                x:Name="PART_VerticalScrollBar"
                                Maximum="{TemplateBinding ScrollableHeight}"
                                HorizontalAlignment="Right"
                                Margin="0,0,-5,0"
                                Orientation="Vertical"
                                Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
                                Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}"
                                ViewportSize="{TemplateBinding ViewportHeight}"/>
                            <ScrollBar
                                Grid.Row="2"
                                Grid.ColumnSpan="2"
                                x:Name="PART_HorizontalScrollBar"
                                Margin="0,0,0,-5"
                                Maximum="{TemplateBinding ScrollableWidth}"
                                Orientation="Horizontal"
                                Value="{Binding HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}"
                                VerticalAlignment="Bottom"
                                ViewportSize="{TemplateBinding ViewportWidth}"
                                Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <DataTrigger Binding="{Binding TemplatedParent.SelectionMode, RelativeSource={RelativeSource TemplatedParent}}" Value="Extended">
                            <Setter TargetName="PART_ScrollContentPresenter" Property="Margin" Value="{Binding Padding, RelativeSource={RelativeSource TemplatedParent}}"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding TemplatedParent.SelectionMode, RelativeSource={RelativeSource TemplatedParent}}" Value="Multiple">
                            <Setter TargetName="PART_ScrollContentPresenter" Property="Margin" Value="{Binding Padding, RelativeSource={RelativeSource TemplatedParent}}"/>
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    <ControlTemplate x:Key="ControlTemplate.DataGrid" TargetType="{x:Type DataGrid}">
        <ScrollViewer 
            x:Name="PART_ScrollViewer" 
            Panel.ZIndex="1"
            Background="{TemplateBinding Background}"
            BorderBrush="{TemplateBinding BorderBrush}"
            BorderThickness="{TemplateBinding BorderThickness}"
            Focusable="False"
            Padding="{TemplateBinding Padding}"
            Style="{StaticResource Style.DataGrid.ScrollViewer}">
            <Grid>
                <ItemsPresenter 
                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                    Margin="{TemplateBinding Padding}"/>
            </Grid>
        </ScrollViewer>
    </ControlTemplate>

    <Style x:Key="{x:Type DataGrid}" TargetType="{x:Type DataGrid}">
        <Setter Property="Controls.Common:DataGridExtensions.ExtendsDefaultBehavior" Value="True"/>
        <Setter Property="AlternationCount" Value="2" />
        <Setter Property="AutoGenerateColumns" Value="False" />
        <Setter Property="Background" Value="{DynamicResource Brush.DataGrid.Background}" />
        <Setter Property="BorderBrush" Value="{DynamicResource Brush.DataGrid.Border}" />
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="CanUserAddRows" Value="False"/>
        <Setter Property="CanUserDeleteRows" Value="False"/>
        <Setter Property="CanUserReorderColumns" Value="True"/>
        <Setter Property="CanUserResizeColumns" Value="True"/>
        <Setter Property="CanUserResizeRows" Value="False"/>
        <Setter Property="CanUserSortColumns" Value="True"/>
        <Setter Property="ColumnHeaderStyle" Value="{StaticResource Style.DataGridColumnHeader}"/>
        <Setter Property="GridLinesVisibility" Value="None"/>
        <Setter Property="HeadersVisibility" Value="Column"/>
        <Setter Property="HorizontalGridLinesBrush" Value="{DynamicResource Brush.DataGrid.GridLines.Horizontal}"/>
        <Setter Property="HorizontalAlignment" Value="Stretch"/>
        <Setter Property="VirtualizingPanel.IsVirtualizing" Value="True" />
        <Setter Property="SelectionMode" Value="Extended"/>
        <Setter Property="SelectionUnit" Value="FullRow"/>
        <Setter Property="Controls.Common:ItemsControlExtensions.SelectNoneOnEmptySpaceClick" Value="True"/>
        <Setter Property="VerticalAlignment" Value="Stretch"/>
        <Setter Property="VerticalGridLinesBrush" Value="{DynamicResource Brush.DataGrid.GridLines.Vertical}"/>
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
        <Setter Property="VirtualizingPanel.VirtualizationMode" Value="Recycling" />
        <Setter Property="Template" Value="{StaticResource ControlTemplate.DataGrid}"/>
    </Style>
</ResourceDictionary>